//
//  NewsHeadCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/20.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import FSPagerView

class NewsHeadCell: FSPagerViewCell {
    
    let backImageView = UIImageView()
    let titleLabel = UILabel()
    let pageLabel = UILabel()
    
    var model : NewsPageModel! {
        didSet{
            updateData()
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.contentView.backgroundColor = UIColor.mineColor()
        
        self.contentView.addSubview(backImageView)
        
        let blackView = UIView()
        blackView.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        backImageView.addSubview(blackView)
        
        titleLabel.textColor = UIColor.white
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 15))
        blackView.addSubview(titleLabel)
        
        pageLabel.textAlignment = .right
        pageLabel.textColor = UIColor.white
        pageLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 15))
        blackView.addSubview(pageLabel)
        
        backImageView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
        
        blackView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        pageLabel.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(RATIO(maxNum: -8))
            make.centerY.equalToSuperview()
            make.width.equalTo(RATIO(maxNum: 30))
            make.height.greaterThanOrEqualTo(10)
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.centerY.equalToSuperview()
            make.height.greaterThanOrEqualTo(10)
            make.right.equalTo(pageLabel.snp.left).offset(RATIO(maxNum: -2))
        }
        
    }
    
    //MARK: 更新数据
    fileprivate func updateData() {
        
        backImageView.setUrlImage(with: kmHttps + (model.image ?? ""), placeholder: UIImage.imageWithName("loading"))
        titleLabel.text = model.title
        pageLabel.text = model.page
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
